package com.app.GoCuro;

import com.app.GoCuro.data.LoginResponse;
import com.app.GoCuro.util.CustomHttpClient;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        
        Button loginButton = (Button) findViewById(R.id.login_button);
        final Context currContext = this;
        loginButton.setOnClickListener(new View.OnClickListener() 
        {
			
			@Override
			public void onClick(View v) 
			{
				CustomHttpClient client = new CustomHttpClient(currContext);
				
				//get the text from the two textboxes
				EditText loginText = (EditText) findViewById(R.id.login_name_text);
				EditText loginPassword = (EditText) findViewById(R.id.login_pw_text);

				LoginResponse loginResponse = client.login(loginText.getText().toString(), loginPassword.getText().toString());
				
				//only start the next activity if you got a non null response to the string
				if (loginResponse != null)
				{					
					Intent selectDatabaseIntent = new Intent(LoginActivity.this, SelectDatabaseActivity.class);
					LoginActivity.this.startActivity(selectDatabaseIntent);
				}
			
			}
		});
    }
}